package com.yj.rabbitClient.config;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory){
        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
        return rabbitTemplate;
    }

    /**
     * 苹果采购队列
     * @return
     */
    @Bean
    public Queue appleQueue(){

        return new Queue("apple-queue");
    }

    /**
     * 香蕉采购队列
     * @return
     */
    @Bean
    public Queue bananaQueue(){

        return new Queue("banana-queue");
    }

    /**
     * 交换机
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("exchange-topic");
    }

    /**
     * 交换机绑定苹果队列
     */
    @Bean
    public Binding appleQueueBindExchange(){
        return BindingBuilder.bind(appleQueue()).to(topicExchange()).with("#.apple.#");
    }

    /**
     * 交换机绑定香蕉队列
     */
    @Bean
    public Binding bananaQueueBindExchange(){
        return BindingBuilder.bind(bananaQueue()).to(topicExchange()).with("#.banana.#");
    }
}
